package com.lin.controller;
import com.lin.domain.Account;
import com.lin.service.IAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
@Controller
@RequestMapping("/account")
public class AccountController {
    @Autowired
    @Qualifier("accountService")
    private IAccountService accountService;

    @RequestMapping("/testFindAll")
    public String  testFindAll(Model model){
        System.out.println("testFindAll执行了");
        List<Account> list = accountService.findAll();
        for (Account account : list) {
            System.out.println(account);
        }
        model.addAttribute("list",list);
        return "success";
    }

    @RequestMapping("/testSave")
    public void  testSave(Account account, HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("testSave-----------");
        accountService.saveAccount(account);
        response.sendRedirect(request.getContextPath()+"/account/testFindAll");
    }

}
